package com.java2207.group1.util;

/**
 * @author HuiCL
 * @version 1.0
 * @date 2022/7/28 11:35
 */
public class DealNumber {

    /**
     * 得到输入的数字的近似值, 例如, 109会被近似为200, 1548会被近似为2000, 3981会被近似为4000
     * @param maximumInMonthBoList
     * @return
     */
    public static int numberForYAxis(Integer maximumInMonthBoList) {

        int base = 10;
        int length = String.valueOf(maximumInMonthBoList).length();

        for (int i = 3; i <= length; i++) {
            base = base * 10;
        }


        if (maximumInMonthBoList > 10) {
            // 比如3981, 先除以base得到3, 然后+1得到4, 然后乘以base即可得到4000
            maximumInMonthBoList = (maximumInMonthBoList / base + 1) * base;
        } else {
            maximumInMonthBoList = 10;
        }

        return maximumInMonthBoList;
    }


}
